/*
 * @Author: shanghongyun 2879455630@qq.com
 * @Date: 2025-06-30 17:25:41
 * @LastEditors: shanghongyun 2879455630@qq.com
 * @LastEditTime: 2025-08-07 16:38:10
 * @FilePath: \A06_From_A05\Device\pga.c
 * @Description: 
 */
#include "dev.h"


/**
 * @description: pga配置
 * @return {*}
 */
void PGA_config(void){
    GPIO_InitTypeStruct PGA_GPIOInitStruct;
    GPIO_StructInit(&PGA_GPIOInitStruct);
    PGA_GPIOInitStruct.GPIO_Pin = LBAT_CUR_PGAP_PIN;
    PGA_GPIOInitStruct.GPIO_PuPd = GPIO_PUPD_NOPULL;
    PGA_GPIOInitStruct.GPIO_OType = GPIO_OTYPE_PP;
    PGA_GPIOInitStruct.GPIO_Mode = GPIO_MODE_ANALOG;
    PGA_GPIOInitStruct.GPIO_Speed = GPIO_SPEED_HIGH;
    GPIO_Init(GPIOA, &PGA_GPIOInitStruct);

    PGA_GPIOInitStruct.GPIO_Pin = LBAT_CUR_PGAN_PIN;
    GPIO_Init(GPIOA, &PGA_GPIOInitStruct);

    PGA_GPIOInitStruct.GPIO_Pin = RBAT_CUR_PGAP_PIN;
    GPIO_Init(GPIOA, &PGA_GPIOInitStruct);

    PGA_GPIOInitStruct.GPIO_Pin = RBAT_CUR_PGAN_PIN;
    GPIO_Init(GPIOA, &PGA_GPIOInitStruct);

    GPIO_AnaAFConfig(GPIOA, LBAT_CUR_PGAP_PIN , GPIO_ANA_AF_1);
    GPIO_AnaAFConfig(GPIOA, LBAT_CUR_PGAN_PIN , GPIO_ANA_AF_1);
    GPIO_AnaAFConfig(GPIOA, RBAT_CUR_PGAP_PIN , GPIO_ANA_AF_1);
    GPIO_AnaAFConfig(GPIOA, RBAT_CUR_PGAN_PIN , GPIO_ANA_AF_1);

    /* PGA Config*/
    PGA_InitTypeStruct PGA_InitStruct;
    PGA_StructInit(&PGA_InitStruct);
    PGA_InitStruct.PGA_Mode = PGA_INPUT_MODE_DIFFERENTIAL;
    PGA_InitStruct.PGA_Gain = PGA_AMP_GAIN33;       //gain = 33x
    PGA_InitStruct.PGA_OffsetSel = PGA_OFFSET_SEL_BANDGAP;
    PGA_InitStruct.PGA_OffsetState = ENABLE;
    PGA_Init(PGA_CH0, &PGA_InitStruct);
    PGA_Init(PGA_CH1, &PGA_InitStruct);
    /* PGA Enable */
    PGA_Cmd(PGA_CH0, ENABLE);
    /* PGA Enable */
    PGA_Cmd(PGA_CH1, ENABLE);

    /* Output filtering circuit, input source selection PGA */
    PGA_FiltSelect(PGA_FILT_SEL_PGA0);
    /* Enable output filtering */
    PGA_FiltCmd(ENABLE);
}
